﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using Medicine.Entity;
using System.Globalization;
using Medicine.Service;
namespace Medicine.View
{
    public partial class AddmedInfo : Form
    {
        private Medicin med;
        private User user;
        public AddmedInfo(Medicin med,User user)
        {
            this.user = user;
            this.med = med;
           
            InitializeComponent();
            setInfo();
        }

        private void button2_Click(object sender, EventArgs e)
        {
            //关闭当前窗口
            this.Close();
        }

        public void setInfo() {
            label2.Text = med.Id.ToString();
            label4.Text = med.Name;
            label6.Text = med.Price.ToString();

        }

        private void button1_Click(object sender, EventArgs e)
        {
            String address = textBox1.Text;
            String remark = richTextBox1.Text;
            Medicine.Entity.Record rec = new Medicine.Entity.Record();
            rec.User_id = user.Id;
            rec.Medicine_id = med.Id;
            rec.Remark = remark;
            rec.Adress = address;
            rec.Time = DateTime.Now.ToString();
            DialogResult result = MessageBox.Show("确定购买？", "警告", MessageBoxButtons.OKCancel, MessageBoxIcon.Question);
            if (result == DialogResult.OK)
            {

                //确定按钮的方法
                RecordService rs = new RecordService();
                rs.buyMedicine(rec);
                this.Close();
              
            }
            else
            {

                this.Close();

                //取消按钮的方法
            }
        }
    }
}
